/**
 * 我的优惠券
 * author wim
 */
import 'package:flutter/material.dart';
import 'package:flutter_custom_bottom_tab_bar/eachtab.dart';
import 'package:flutter_custom_bottom_tab_bar/tabbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../base/Constant.dart';
import './MyCouponSub.dart';

class MyCouponPage extends StatefulWidget {
  MyCouponPage({Key key}) : super(key: key);

  @override
  _MyCouponPageState createState() => _MyCouponPageState();
}

class _MyCouponPageState extends State<MyCouponPage>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  var titles = ['可使用', '已使用', '已过期'];
  TabController _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController =
        new TabController(vsync: this, initialIndex: 0, length: titles.length);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          "我的优惠券",
          style: TextStyle(
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
              color: Colors.black),
        ),
        elevation: 0.5,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
      ),
      body: Column(
        children: <Widget>[
          TabContainer(
              // alignment: Alignment.center,
              color: white,
              child: Stack(
                overflow: Overflow.clip,
                children: <Widget>[
                  Center(
                    child: new TabBar(
                      isScrollable: true,
                      controller: _tabController,
                      indicatorColor: mainColor,
                      labelColor: mainColor,
                      labelPadding: EdgeInsets.all(0),
                      unselectedLabelColor: Colors.black,
                      tabs: <Widget>[
                        EachTab(
                          padding: EdgeInsets.fromLTRB(
                              MediaQuery.of(context).size.width / 12,
                              0,
                              MediaQuery.of(context).size.width / 12,
                              0),
                          text: titles[0],
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                        EachTab(
                          text: titles[1],
                          padding: EdgeInsets.fromLTRB(
                              MediaQuery.of(context).size.width / 12,
                              0,
                              MediaQuery.of(context).size.width / 12,
                              0),
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                        EachTab(
                          text: titles[2],
                          padding: EdgeInsets.fromLTRB(
                              MediaQuery.of(context).size.width / 12,
                              0,
                              MediaQuery.of(context).size.width / 12,
                              0),
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                      ],
                    ),
                  ),
                ],
              )),
          Expanded(
            child: TabBarView(controller: _tabController, children: <Widget>[
              Center(
                  child: MyCouponSubPage(
                type: 0,
              )),
              Center(
                  child: MyCouponSubPage(
                type: 1,
              )),
              Center(
                  child: MyCouponSubPage(
                type: 2,
              )),
            ]),
          )
        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
